<?php
	session_start();
?>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
   <meta charset="utf-8">
		<meta name="description" content="">
		<meta name="author" content="">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
		<!--  browser icon  -->
        <link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
		<script src="//cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
		<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
		
		<!--[if lt IE 8]>
		<![endif]-->
		<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
		<!--[if lt IE 9]><script src="SnpsTMC//assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
		
		
		<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
		<!--[if lt IE 9]>
		  <script src="SnpsTMC/assets/default/html5shiv.min.js"></script>
		  <script src="SnpsTMC/assets/default/respond.min.js"></script>
		<![endif]-->
		<title>Synopsys Toaster Master Club Message Wall</title>
		<style type="text/css">
			.foot-front-printer {
				position:fixed;
				bottom:0px;
				width: 100%;
				background: #121212;
				padding:10px 0px;
				font-size: 14px;
				font-family:'Microsoft Yahei';
				color: #CDCDCD;
			}
			body { padding-bottom:40px}
			
			.item {width:150px; height:25px;}
			
			.sel {
				  height: 34px;
				  padding: 6px 12px;
				  font-size: 14px;
				  line-height: 1.42857143;
				  color: #555;
				  background-color: #fff;
				  background-image: none;
				  border: 1px solid #ccc;
				  border-radius: 4px;
				  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
				          box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
				  -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
				       -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
				          transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
			}
		</style>
  </head>

  <body>
	<!-- Static navbar -->
    <nav class="navbar navbar-inverse navbar-static-top" style="background-color: #00B38A;color:white">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" style="color:white" href="#">Synopsys Initial Toastmaster Club</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
       
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container">

        <div class="form-horizontal">
            <h2 >Your Cell Phone: </h2>
            <p class="help-inline">Note: Cell phone is your unique id to distribute message.</p>
            <input type="cellphone" id="inputCellphone" name="cellphone" class="form-control" placeholder="Cell Phone" required autofocus><br>
            
            <h2 class="form-signin-heading">Your Comment: </h2>
            <p class="help-inline">Note: Please obey TMC four toboos, all submitted comment will be audited by admin, so only valid comment will be shown on the message wall~~</p>
       		<textarea rows="5" class="form-control" id="inputComment" name="comment" placeholder="Anything you want to say to Synopsys TMC"  required autofocus></textarea>
        <div class="checkbox"  style="padding:10px 0px">
          <label>
              <input type="checkbox" name="admin"> Admin
          </label>
        </div>
            <button class="btn btn-block btn-primary " id="go" type="submit" style="background-color:#00B38A">Distribute</button>
        <button class="btn btn-block btn-primary " id="view" style="background-color:#00B38A">View the comment directly</button>
      </div>

    </div> <!-- /container -->

	<div class="foot-front-printer" style="background-color: #00B38A;color:white">
			<div class="container text-center">
				Synopsys TMC Copyright © 2014-<?php echo date('Y',time());?>
			</div>
		</div>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!--  <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->
      <script type="text/javascript">
      		var toValid;
			$(document).ready(function() {				
			
                String.prototype.trim=function() {
                    return this.replace(/(^\s*)|(\s*$)/g,'');
                };
                
                 $("#view").click(function () {
                     var cellphone = $('#inputCellphone').val();
                     if(cellphone.trim() == "") {
                         alert("Cell phone cannot be empty!");
                         return false;
                     }
                     
                     if($("input[type='checkbox']").is(':checked')) {
                         $.ajax({
                             type : 'POST',
                             url : 'controller/check_admin.php',
                             dataType : 'json',
                             data : {
                                 cellphone: cellphone
                             },
                             success : function(resJson, textStatus){
                               
                                 if(resJson.status == "success") {
                                     <?php
                                     $_SESSION["admin"] = 1;
									?>
                                     location.href="controller/main.php?admin=1";
                                 } else {
                                     alert(resJson.msg);
                                     location.href="controller/main.php";
                                 }
                                 
                             },
                             error : function(XMLHttpRequest, textStatus, errorThrown) {
                                 return false;
                             }
                         });
                        
                     } else {
                         is_admin = 0;
                         location.href="controller/main.php"; 
                     }
                    
                });
                                 
                                 
                $("#go").click(function () {
                    var cellphone = $('#inputCellphone').val();
                    if(cellphone.trim() == "") {
                        alert("Cell phone cannot be empty!");
                        return false;
                    }
                    
                    var re = /^1\d{10}$/;
                    if(!re.test(cellphone.trim())) {
                        alert("Cellphone format is wrong!");
                        return false;
                    }
                    
                    var comment = $('#inputComment').val();
                    if(comment.trim() == "") {
                        alert("Comment cannot be empty!");
                        return false;
                    }


                   	if($("input[type='checkbox']").is(':checked')) {
                       	is_admin = 1;
                    } else {
                        is_admin = 0;
                    }
                    
                    $.ajax({
                            type : 'POST',
                            url : 'controller/ajax_query.php',
                            dataType : 'json',
                            data : {
                                cellphone: cellphone,
                                comment: comment,
                                is_admin: is_admin
                            },
                            success : function(resJson, textStatus){
 								alert(resJson.msg);
                                if(resJson.status == "success") {
                                    if(is_admin == "1") {
                                        location.href="controller/main.php?admin=1";
                                    } else {
                                    	location.href="controller/main.php";
                                    }
                                }
                               
                            },
                            error : function(XMLHttpRequest, textStatus, errorThrown) {
                                return false;
                            }
                   	 	})
                    
                    return true;
                });                
			 
			});
			
		</script>
  </body>
</html>